import { Prefab, resources } from "cc";
import { Ab_Defeat_bA } from "./popup.defeat";
import { Ab_DrawerLock_bA } from "./popup.drawer.lock";
import { Ab_Free_bA } from "./popup.free";
import { Ab_FruitDiamond_bA } from "./popup.fruit.diamond";
import { Ab_FruitSpecial_bA } from "./popup.fruit.special";
import { Ab_LuckyBox_bA } from "./popup.luckybox";
import { Ab_Prop_bA } from "./popup.prop";
import { Ab_Rank_bA } from "./popup.rank";
import { Ab_Resurgence_bA } from "./popup.resurgence";
import { Ab_Setting_bA } from "./popup.setting";
import { Ab_Tast_bA } from "./popup.task";
import { Ab_Victory_bA } from "./popup.victory";

export enum Ab_EPopup_bA {
	Ab_DEFEAT_bA,
	Ab_DRAWER_LOCK_bA,
	Ab_FREE_bA,
	Ab_FRUIT_DIAMOND_bA,
	Ab_FRUIT_SPECIAL_bA,
	Ab_LUCKYBOX_bA,
	Ab_PROP_bA,
	Ab_RANK_bA,
	Ab_RESURGENCE_bA,
	Ab_SETTING_bA,
	Ab_TASK_bA,
	Ab_VICTORY_bA,
}

const Ab_CONFIG_bA = {
	[Ab_EPopup_bA.Ab_DEFEAT_bA]: {
		component: Ab_Defeat_bA,
		path: 'prefab/pop-up/defeat',
		script: './popup.defeat.ts',
		prefab: null
	},
	[Ab_EPopup_bA.Ab_DRAWER_LOCK_bA]: {
		component: Ab_DrawerLock_bA,
		path: 'prefab/pop-up/drawer-lock',
		script: './popup.drawer.lock.ts',
		prefab: null
	},
	[Ab_EPopup_bA.Ab_FREE_bA]: {
		component: Ab_Free_bA,
		path: 'prefab/pop-up/free',
		script: './popup.free.ts',
		prefab: null
	},
	[Ab_EPopup_bA.Ab_FRUIT_DIAMOND_bA]: {
		component: Ab_FruitDiamond_bA,
		path: 'prefab/pop-up/fruit-diamond',
		script: './popup.fruit.diamond.ts',
		prefab: null
	},
	[Ab_EPopup_bA.Ab_FRUIT_SPECIAL_bA]: {
		component: Ab_FruitSpecial_bA,
		path: 'prefab/pop-up/fruit-special',
		script: './popup.fruit.special.ts',
		prefab: null
	},
	[Ab_EPopup_bA.Ab_LUCKYBOX_bA]: {
		component: Ab_LuckyBox_bA,
		path: 'prefab/pop-up/lucky-box',
		script: './popup.luckybox.ts',
		prefab: null
	},
	[Ab_EPopup_bA.Ab_PROP_bA]: {
		component: Ab_Prop_bA,
		path: 'prefab/pop-up/prop',
		script: './popup.prop.ts',
		prefab: null
	},
	[Ab_EPopup_bA.Ab_RANK_bA]: {
		component: Ab_Rank_bA,
		path: 'prefab/pop-up/rank',
		script: './popup.rank.ts',
		prefab: null
	},
	[Ab_EPopup_bA.Ab_RESURGENCE_bA]: {
		component: Ab_Resurgence_bA,
		path: 'prefab/pop-up/resurgence',
		script: './popup.resurgence.ts',
		prefab: null
	},
	[Ab_EPopup_bA.Ab_SETTING_bA]: {
		component: Ab_Setting_bA,
		path: 'prefab/pop-up/setting',
		script: './popup.setting.ts',
		prefab: null
	},
	[Ab_EPopup_bA.Ab_TASK_bA]: {
		component: Ab_Tast_bA,
		path: 'prefab/pop-up/task',
		script: './popup.task.ts',
		prefab: null
	},
	[Ab_EPopup_bA.Ab_VICTORY_bA]: {
		component: Ab_Victory_bA,
		path: 'prefab/pop-up/victory',
		script: './popup.victory.ts',
		prefab: null
	},
}

export async function Ab_GetPopPrefab_bA(p: Ab_EPopup_bA): Promise<Prefab> {
	let conf = Ab_CONFIG_bA[p];
	if(!conf.prefab){
		conf.prefab = await abi.Ab_cc_bA.Ab_loadResAsync_bA(conf.path, Prefab, resources);
	}

	return conf.prefab;
}

export async function Ab_GetPopComponent_bA<P extends Ab_EPopup_bA>(p: P): Promise<(typeof Ab_CONFIG_bA)[P]['component']> {
	let conf = Ab_CONFIG_bA[p];
	if(!conf.component){
		conf.component = await import(conf.script).then(m=>m.default);
	}

	return conf.component;
}

export type Ab_PopCtor_bA<P extends Ab_EPopup_bA> = typeof Ab_CONFIG_bA[P]['component'];

export type Ab_PopIns_bA<P extends Ab_EPopup_bA> = InstanceType<Ab_PopCtor_bA<P>>;

export type Ab_PopParams_bA<P extends Ab_EPopup_bA> = Parameters<Ab_PopIns_bA<P>['Ab_onShow_bA']>;

export type Ab_PopReturn_bA<P extends Ab_EPopup_bA> = Awaited<ReturnType<Ab_PopIns_bA<P>['Ab_show_bA']>>;